package com.czp.job.action;

import com.czp.framework.action.BaseActionSupport;
import com.czp.framework.exception.IServiceException;
import com.czp.job.model.Job;
import com.czp.job.model.RelationPerson;
import com.czp.job.service.IJobService;

/**
 * 【环 境】：J2SE 1.7
 * @author   柴志鹏	CHAIZP@GMAIL.COM
 * @version  version 1.0
 * @since    2014-7-17
 */
public class JobAction extends BaseActionSupport {
	private static final long serialVersionUID = -8912156379879665869L;
	private IJobService jobService;
	private Job job;
	
	/** 
	 * 【描 述】：查询岗位信息
	 */
	public void queryJobList() {
		Job job = new Job();
		try {
			job.setStart(Integer.parseInt(request.getParameter("start")));
			job.setLimit(Integer.parseInt(request.getParameter("limit")));
			this.responseOutPrint(
					jobService.queryJobList(job));
		} catch(Exception e) {
			throw new IServiceException(this.getClass()+ "queryJobList", e);
		}
	}
	
	/** 
	 * 【描 述】：添加、修改岗位信息
	 */
	public void jobController() {
		try {
			int count = jobService.jobController(job);
			this.responseOutPrint("{success:"+ count +"}");
		} catch(Exception e) {
			throw new IServiceException(this.getClass()+ "jobController", e);
		}
	}
	
	/** 
	 * 【描 述】：根据岗位Id查选下属岗位
	 */
	public void querySubordinateByJobId() {
		try {
			String jobId = request.getParameter("jobId");
			this.responseOutPrint(
					jobService.querySubordinateByJobId(jobId));
		} catch(Exception e) {
			throw new IServiceException(this.getClass()+ "querySubordinateByJobId", e);
		}
	}
	
	/** 
	 * 【描 述】：根据岗位Id查询人员信息
	 */
	public void queryPersonByJobId() {
		try {
			String jobId = request.getParameter("jobId");
			this.responseOutPrint(
					jobService.queryPersonByJobId(jobId));
		} catch(Exception e) {
			throw new IServiceException(this.getClass()+ "queryPersonByJobId", e);
		}
	}
	
	/** 
	 * 【描 述】：取消下属岗位
	 */
	public void deleteRelationJob() {
		try {
			String jsonData = request.getParameter("jsonData");
			this.responseOutPrint(
					jobService.deleteRelationJob(jsonData));
		} catch(Exception e) {
			throw new IServiceException(this.getClass()+ "deleteRelationJob", e);
		}
	}
	
	/** 
	 * 【描 述】：删除关联岗位人员信息
	 */
	public void deleteRelationPerson() {
		try {
			String jsonData = request.getParameter("jsonData");
			this.responseOutPrint(
					jobService.deleteRelationPerson(jsonData));
		} catch(Exception e) {
			throw new IServiceException(this.getClass()+ "deleteRelationPerson", e);
		}
	}
	
	/** 
	 * 【描 述】：查询全部人员与被选中人员信息
	 */
	public void getSelectedPersonList() {
		RelationPerson relPerson = new RelationPerson();
		try {
			relPerson.setStart(Integer.parseInt(request.getParameter("start")));
			relPerson.setLimit(Integer.parseInt(request.getParameter("limit")));
			relPerson.setJobId(request.getParameter("jobId"));
			relPerson.setPersonName(request.getParameter("personName"));
			this.responseOutPrint(
					jobService.getSelectedPersonList(relPerson));
		} catch(Exception e) {
			throw new IServiceException(this.getClass()+ "getSelectedPersonList", e);
		}
	}
	
	/** 
	 * 【描 述】：授权、取消人员信息
	 */
	public void relationPersonController() {
		try {
			String jsonData = request.getParameter("jsonData");
			this.responseOutPrint(
					jobService.relationPersonController(jsonData));
		} catch(Exception e) {
			throw new IServiceException(this.getClass()+ "relationPersonController", e);
		}
	}
	
	/** 
	 * 【描 述】：获取可选岗位
	 */
	public void getOptionalJob() {
		try {
			String jobId = request.getParameter("jobId");
			this.responseOutPrint(
					jobService.getOptionalJob(jobId));
		} catch(Exception e) {
			throw new IServiceException(this.getClass()+ "getOptionalJob", e);
		}
	}
	
	/** 
	 * 【描 述】：获取已选岗位
	 */
	public void getSelectedJob() {
		try {
			String jobId = request.getParameter("jobId");
			this.responseOutPrint(
					jobService.getSelectedJob(jobId));
		} catch(Exception e) {
			throw new IServiceException(this.getClass()+ "getSelectedJob", e);
		}
	}
	
	/** 
	 * 【描 述】：操作下属分配
	 */
	public void relationJobController() {
		try {
			String jsonData = request.getParameter("data");
			System.out.println(jsonData);
			int count = jobService.relationJobController(jsonData);
			this.responseOutPrint("{success:"+ count +"}");
		} catch(Exception e) {
			throw new IServiceException(this.getClass()+ "relationJobController", e);
		}
	}
	
	/**
	 * 获取 jobService
	 * @return 返回 jobService
	 */
	public IJobService getJobService() {
		return jobService;
	}
	/**
	 * 设置 jobService
	 * @param 对jobService进行赋值
	 */
	public void setJobService(IJobService jobService) {
		this.jobService = jobService;
	}
	/**
	 * 获取 job
	 * @return 返回 job
	 */
	public Job getJob() {
		return job;
	}
	/**
	 * 设置 job
	 * @param 对job进行赋值
	 */
	public void setJob(Job job) {
		this.job = job;
	}
	
}
